<template>
  <div>
    <!-- 最上面 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 第一层搜索框和按钮 -->
      <el-input placeholder="请输入搜索内容" style="width: 400px">
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <el-button type="primary">添加用户</el-button>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      usersParams: {
        query: "",
        pagenum: 1,
        pagesize: 2
      },
      usersList: [],
      total: 0
    };
  },
  created() {
    this.gutUserList();
  },
  methods: {
    async gutUserList() {
      //为什么这里的参数要写成 {params：}的形式呢？
      const { data: res } = await this.$http.get("users", {
        params: this.usersParams
      });
      if (res.meta.status !== 200) {
        return this.$message.error("获取用户列表失败");
      }
      console.log(res);
      this.usersList = res.data.users;
      this.total = res.data.total;
      console.log(this.usersList);
    }
  }
};
</script>

<style lang="less">
.el-card {
  margin-top: 15px;
}
.el-card .el-button {
  margin-left: 20px;
}
</style>
